package utils;

import cn.hutool.http.HttpUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @Author: DRevelation
 * @Date: 2020/12/5 13:41
 */
public class UploadHtmlUtils {
    public static void main(String[] args) {
        String url = "https://baijiahao.baidu.com/s?id=1684932970194366840&wfr=spider&for=pc";

        String sourceCode = HttpUtil.get(url);
        Document doc = Jsoup.parse(sourceCode);
        String title = doc.select("title").text();
        System.out.println("title = " + title);
//        String videoUrl = doc.select("video").attr("src");
//        System.out.println("videoUrl = " + videoUrl);
        Elements elements = doc.select(".article").select("img");
        Elements elements2 = doc.select(".article").select("video");
        elements.addAll(elements2);
        for (Element element : elements) {
            String imgUrl = element.attr("src");
            if (!imgUrl.startsWith("http:")) {
                System.out.println("http:" + imgUrl);
            }
        }
    }
}
